home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / multiclr.lha / MC / mc_bleed.c < prev    next >
C/C++ Source or Header  |  1995-10-02  |  7KB  |  258 lines

  1. /******************************************************************************
  2. **                                                                           **
  3. ** MultiColor-Demo-Bleed                                                     **
  4. **                                                                           **
  5. **---------------------------------------------------------------------------**
  6. ** V2.0 vom 01.10.95                                                         **
  7. ******************************************************************************/
  8.  
  9. #include "sc:source/mc/multicolor.h"
  10.  
  11. /* Protos */
  12.  
  13. void OpenAll(void);
  14. void CloseAll(void);
  15. void Bleed(UWORD eg1,UWORD eg2,UWORD eg3,UWORD eg4);
  16. void Usage(void);
  17.  
  18. /* defines */
  19.  
  20. extern struct ExecBase         *SysBase;
  21. struct IntuitionBase        *IntuitionBase=0l;
  22. struct GfxBase                 *GfxBase=0l;
  23. struct Screen                *scr=0l;
  24. struct Window                *win=0l;
  25. MCHandle                    *mch=0l;
  26.  
  27. struct TagItem scrtags[]={
  28.     SA_Left,        0,
  29.     SA_Top,            0,
  30.     SA_Width,        0,
  31.     SA_Height,        0,
  32.     SA_Depth,        0,
  33.     SA_Colors,        0l,
  34.     SA_Type,        CUSTOMSCREEN,
  35.     SA_DisplayID,    PAL_MONITOR_ID,
  36.     TAG_DONE
  37. };
  38.  
  39. struct TagItem wintags[]={
  40.     WA_Left,        0,
  41.     WA_Top,            0,
  42.     WA_Width,        0,
  43.     WA_Height,        0,
  44.     WA_IDCMP,        IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  45.     WA_Flags,        WFLG_SMART_REFRESH|WFLG_RMBTRAP|WFLG_BORDERLESS|WFLG_ACTIVATE,
  46.     WA_CustomScreen,0l,
  47.     TAG_DONE
  48. };
  49.  
  50. /* Funktions */
  51.  
  52. void OpenAll(void)
  53. {
  54. //    if(!(IntuitionBase=OpenLibrary("intuition.library",37))) CloseAll();
  55.     if(!(IntuitionBase=OpenLibrary("intuition.library",39))) CloseAll();
  56.     if(!(GfxBase=OpenLibrary("graphics.library",37))) CloseAll();
  57.  
  58.     if(!(scr=OpenScreenTagList(0l,scrtags))) CloseAll();
  59.     wintags[6].ti_Data=scr;
  60.  
  61.     if(!(win=OpenWindowTagList(0l,wintags))) CloseAll();
  62. }
  63.  
  64. void CloseAll(void)
  65. {
  66.     if(win)                CloseWindow(win);
  67.     if(scr)                CloseScreen(scr);
  68.     if(GfxBase)            CloseLibrary(GfxBase);
  69.     if(IntuitionBase)    CloseLibrary(IntuitionBase);
  70.     exit(0);
  71. }
  72.  
  73. void Bleed(UWORD eg1,UWORD eg2,UWORD eg3,UWORD eg4)
  74. {
  75.     struct IntuiMessage *imsg;
  76.     ULONG iclass;
  77.     USHORT icode;
  78.     register UBYTE quit=0;
  79.     register UWORD x,y;
  80.     MCPoint edge[4],akt,t1,t2;
  81.     MCPoint v1d,v1s,v2d,v2s,h1d,h1s;
  82. //    FILE *filer=0l,*fileg=0l,*fileb=0l;
  83. //    UBYTE color;
  84.  
  85.     edge[0].r=(double)((eg1&0xF00)>>8)/16.0;edge[0].g=(double)((eg1&0x0F0)>>4)/16.0;edge[0].b=(double)(eg1&0x00F)/16.0;
  86.     edge[1].r=(double)((eg2&0xF00)>>8)/16.0;edge[1].g=(double)((eg2&0x0F0)>>4)/16.0;edge[1].b=(double)(eg2&0x00F)/16.0;
  87.     edge[2].r=(double)((eg3&0xF00)>>8)/16.0;edge[2].g=(double)((eg3&0x0F0)>>4)/16.0;edge[2].b=(double)(eg3&0x00F)/16.0;
  88.     edge[3].r=(double)((eg4&0xF00)>>8)/16.0;edge[3].g=(double)((eg4&0x0F0)>>4)/16.0;edge[3].b=(double)(eg4&0x00F)/16.0;
  89.  
  90.     v1d.r=edge[3].r-edge[0].r;v1s.r=v1d.r/(double)mch->yres;
  91.     v1d.g=edge[3].g-edge[0].g;v1s.g=v1d.g/(double)mch->yres;
  92.     v1d.b=edge[3].b-edge[0].b;v1s.b=v1d.b/(double)mch->yres;
  93.     v2d.r=edge[2].r-edge[1].r;v2s.r=v2d.r/(double)mch->yres;
  94.     v2d.g=edge[2].g-edge[1].g;v2s.g=v2d.g/(double)mch->yres;
  95.     v2d.b=edge[2].b-edge[1].b;v2s.b=v2d.b/(double)mch->yres;
  96.  
  97. //    filer=fopen("xh3:test.r","wb");
  98. //    fileg=fopen("xh3:test.g","wb");
  99. //    fileb=fopen("xh3:test.b","wb");
  100.  
  101. //    if(filer && fileg && fileb)
  102. //    {
  103.         for(y=0;y<mch->yres;y++)
  104.         {
  105.             t1.r=edge[0].r+((double)y*v1s.r);
  106.             t1.g=edge[0].g+((double)y*v1s.g);
  107.             t1.b=edge[0].b+((double)y*v1s.b);
  108.             t2.r=edge[1].r+((double)y*v2s.r);
  109.             t2.g=edge[1].g+((double)y*v2s.g);
  110.             t2.b=edge[1].b+((double)y*v2s.b);
  111.             h1d.r=t2.r-t1.r;h1s.r=h1d.r/(double)mch->xres;
  112.             h1d.g=t2.g-t1.g;h1s.g=h1d.g/(double)mch->xres;
  113.             h1d.b=t2.b-t1.b;h1s.b=h1d.b/(double)mch->xres;
  114.             for(x=0;x<mch->xres;x++)
  115.             {
  116.                 akt.r=t1.r+((double)x*h1s.r);
  117.                 akt.g=t1.g+((double)x*h1s.g);
  118.                 akt.b=t1.b+((double)x*h1s.b);
  119. //                color=(UBYTE)(255.0*akt.r);fwrite(&color,1,1,filer);
  120. //                color=(UBYTE)(255.0*akt.g);fwrite(&color,1,1,fileg);
  121. //                color=(UBYTE)(255.0*akt.b);fwrite(&color,1,1,fileb);
  122.                 MC_PutPixel(mch,x,y,akt);
  123.             }
  124.         }
  125. //        fclose(fileb);
  126. //        fclose(fileg);
  127. //        fclose(filer);
  128. //    }
  129.     while(!quit)
  130.     {
  131.         WaitPort(win->UserPort);
  132.         while(imsg=GetMsg(win->UserPort))
  133.         {
  134.             iclass    =imsg->Class;
  135.             icode    =imsg->Code;
  136.             ReplyMsg(imsg);
  137.             switch(iclass)
  138.             {
  139.                 case IDCMP_RAWKEY:
  140.                     switch(icode)
  141.                     {
  142.                         case 0x45:        /* ESC */
  143.                         case 0x40:        /* Space */
  144.                             quit=1;break;
  145.                     }
  146.                     break;
  147.             }
  148.         }
  149.     }
  150. }
  151.  
  152. void Usage(void)
  153. {
  154.     printf("Usage \n");
  155.     printf("\tmc_bleed typ res\n");
  156.     printf("\tres\typ | 0=ECS | 1=AGA,GFX-Card\n");
  157.     printf("\t--------+-------+---------------\n");
  158.     printf("\t e (ehb)| 64    | -             \n");
  159.     printf("\t l (low)| 32    | 256           \n");
  160.     printf("\t h (hi )| 16    | 256           \n");
  161.     printf("\t s (shi)| --    | 256           \n");
  162.     printf("\t--------+-------+---------------\n");
  163. }
  164.  
  165. void main(int argc,char *argv[])
  166. {
  167.     UBYTE dep,typ,fail=0;
  168.     char res;
  169.     UWORD eg1=0x0F0,eg2=0x0FF,eg3=0xF0F,eg4=0xFF0;
  170.  
  171.     if(argc>=3)
  172.     {
  173.         typ=atoi(argv[1])&1;
  174.         res=argv[2][0];
  175.         if(argc>=4) eg1=atoi(argv[3]);
  176.         if(argc>=5) eg2=atoi(argv[4]);
  177.         if(argc>=6) eg3=atoi(argv[5]);
  178.         if(argc>=7) eg4=atoi(argv[6]);
  179.  
  180.         switch(typ)
  181.         {
  182.             case 0:        /* ECS */
  183.                 switch(res)
  184.                 {
  185.                     case 'E':
  186.                     case 'e':
  187.                         scrtags[4].ti_Data=dep=6;
  188.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  189.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  190.                         scrtags[7].ti_Data|=EXTRAHALFBRITELACE_KEY;
  191.                         break;
  192.                     case 'L':
  193.                     case 'l':
  194.                         scrtags[4].ti_Data=dep=5;
  195.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  196.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  197.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  198.                         break;
  199.                     case 'H':
  200.                     case 'h':
  201.                         scrtags[4].ti_Data=dep=4;
  202.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  203.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  204.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  205.                         break;
  206.                     case 'S':
  207.                     case 's':
  208.                         fail=1;
  209.                         break;
  210.                 }
  211.                 break;
  212.             case 1:        /* AGA,GFX-Card */
  213.                 switch(res)
  214.                 {
  215.                     case 'E':
  216.                     case 'e':
  217.                         fail=1;
  218.                         break;
  219.                     case 'L':
  220.                     case 'l':
  221.                         scrtags[4].ti_Data=dep=8;
  222.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  223.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  224.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  225.                         break;
  226.                     case 'H':
  227.                     case 'h':
  228.                         scrtags[4].ti_Data=dep=8;
  229.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  230.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  231.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  232.                         break;
  233.                     case 'S':
  234.                     case 's':
  235.                         scrtags[4].ti_Data=dep=8;
  236.                         wintags[2].ti_Data=scrtags[2].ti_Data=1416;        /* 944 */
  237.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  238.                         scrtags[7].ti_Data|=SUPERLACE_KEY;
  239.                         break;
  240.                 }
  241.                 break;
  242.         }
  243.  
  244.         if(!fail)
  245.         {
  246.             OpenAll();
  247.             if(mch=MC_Init(scr,win,dep))
  248.             {
  249.                 Bleed(eg1,eg2,eg3,eg4);
  250.                 MC_Free(mch);
  251.             }
  252.         }
  253.         else Usage();
  254.     }
  255.     else Usage();
  256.     CloseAll();
  257. }
  258.